%function graficar angulos del robot planar 3 links, tarea2a()
% plot_X_pf_free grafica los datos asociados al nombre 
%Rta de posicion, en el esquema p-p, sin contacto
% Datos a graficar position_pf_free.mat
% 1ra fila: punto
% 2da fila: theta1
% 3ra fila: theta2
% 3ra fila: theta3
% se debe correr el archivo tarea2a.m
clc;
%clear all;
%cargamos los datos
%load D:\Users\Javier\Documents\MATLAB\Modelo_teleop\Modelo_teleop\Modelo_teleop\p-f\graficas\mat-files\position_pf_free.mat;
%DONDE GUARDAR LA FIGURA EN PDF
strFilePath = 'D:\Users\Javier\Documents\MATLAB\RoboticaUN\metodos_cinematica\tarea2\a\figuras\tarea2a';
t=0:1:19;
numDatos=size(t);
theta1= 180*theta(1,:)/pi;
theta2= 180*theta(2,:)/pi;
theta3= 180*theta(3,:)/pi;
%-----------------------------------------
%Propiedades importantes de la figura:
%-----------------------------------------
%dimension de la figura :
width_x = 9;
width_y = 5;
% limites de los ejes:
limX= [0 numDatos(2)+2];
limY= [-180 180];
%tamano de la letra
iFontSize = 10;
%grosor de la linea de los ejes
fLineWidth = 1; % width of the line of the axes
% Las leyendas de los ejes:
strXLabel = 'points';
strYLabel = 'degrees';
%%
% we set the units of the measures used through the file
%
% [ inches | centimeters | normalized | points | {pixels} | characters ]
set(gcf, 'Units', 'centimeters');
% we set the position and dimension of the figure ON THE SCREEN
%
% NOTE: measurement units refer to the previous settings!
afFigurePosition = [1 1 width_x width_y]; % [pos_x pos_y width_x width_y]
set(gcf, 'Position', afFigurePosition); % [left bottom width height]
% we link the dimension of the figure ON THE PAPER in such a way that
% it is equal to the dimension on the screen
%
% ATTENTION: if PaperPositionMode is not �auto� the saved file
% could have different dimensions from the one shown on the screen!
set(gcf, 'PaperPositionMode', 'auto');
%%

%---------------------------------------------------------
%Configurar axes, para mas propiedades ver axes_figure.m
%---------------------------------------------------------
% general properties
strFontUnit = 'points'; % [{points} | normalized | inches | centimeters | pixels]
strFontName = 'Times'; % [Times | Courier | ] TODO complete the list
strFontWeight = 'normal'; % [light | {normal} | demi | bold]
strFontAngle = 'normal'; % [{normal} | italic | oblique] ps: only for axes
strInterpreter = 'latex'; % [{tex} | latex]
set(gca, ...
     'XColor', [.1 .1 .1], ... color of x axis
 'YColor', [.1 .1 .1], ... color of y axis
  'XLim', limX, ... limits for the x-axis
 'YLim', limY, ... limits for the y-axis
'FontName', strFontName, ... kind of fonts of labels
'FontSize', iFontSize, ... size of fonts of labels
'FontUnits', strFontUnit, ... units of the size of fonts
'FontWeight', strFontWeight, ... weight of fonts of labels
'FontAngle', strFontAngle, ... inclination of fonts of labels
'LineWidth', fLineWidth,'XGrid', 'off','YGrid', 'off'); % width of the line of the axes


%Labels de axes
%
fXLabelRotation = 0.0;
fYLabelRotation = 90.0;
xlabel( strXLabel, ...
'FontName', strFontName, ...
'FontUnit', strFontUnit, ...
'FontSize', iFontSize, ...
'FontWeight', strFontWeight, ...
'Interpreter', strInterpreter);
%
ylabel( strYLabel, ...
'FontName', strFontName, ...
'FontUnit', strFontUnit, ...
'FontSize', iFontSize, ...
'FontWeight', strFontWeight, ...
'Interpreter', strInterpreter);
%
set(get(gca, 'XLabel'), 'Rotation', fXLabelRotation);
set(get(gca, 'YLabel'), 'Rotation', fYLabelRotation);

% in order to make matlab to do not "cut" latex-interpreted axes labels
set(gca, 'Units','normalized','Position',[0.15 0.2 0.75 0.7]);
%%
%--------------------------------------------------
%Graficas de los datos - ver properties_figure.m
%--------------------------------------------------
% 1ra grafica - theta1
% 2da  "      - theta2
% 3da  "      - theta3
% -- lines
%******************************************************************
afPlotLineWidth = [1, 1, 1];
%******************************************************************
astrPlotLineStyle = [{'-'}, {'--'}, {'-.'}]; % NOTE: do not insert '.-' but '-.'
aafPlotLineColor = [[0.1 0.1 0.1] ; [0.2 0.2 0.2];[0.4 0.4 0.4]]; % RGB
%
% -- markers
aiPlotMarkerSize = [0.5, 0.5, 0.5]; % in points
astrPlotMarkerType = [{'none'},{'+'},{'none'}]; %[{'.'},{'+'},{'x'}]
aafPlotMarkerFaceColor = [[0.1 0.1 0.1] ; [0.2 0.2 0.2];[0.5 0.5 0.5]]; % RGB
aafPlotMarkerEdgeColor = [[0.3 0.3 0.3] ; [0.4 0.4 0.4];[0.6 0.6 0.6]]; % RGB
% we want to plot several curves
hold on;
%
% here you can plot several plots (each can have its properties)
% note: it is convenient to store the handles to the single plots
% in order to easily manage legends
%
fig_theta1 = plot( ...
t, ...
theta1, ...
'LineStyle', astrPlotLineStyle{1}, ...
'LineWidth', afPlotLineWidth(1), ...
'Color', aafPlotLineColor(1,:), ...
'MarkerSize', aiPlotMarkerSize(1), ...
'Marker', astrPlotMarkerType{1}, ...
'MarkerFaceColor', aafPlotMarkerFaceColor(1,:), ...
'MarkerEdgeColor', aafPlotMarkerEdgeColor(1,:));

fig_theta2 = plot( ...
t, ...
theta2, ...
'LineStyle', astrPlotLineStyle{2}, ...
'LineWidth', afPlotLineWidth(2), ...
'Color', aafPlotLineColor(2,:), ...
'MarkerSize', aiPlotMarkerSize(2), ...
'Marker', astrPlotMarkerType{2}, ...
'MarkerFaceColor', aafPlotMarkerFaceColor(2,:), ...
'MarkerEdgeColor', aafPlotMarkerEdgeColor(2,:));

fig_theta3 = plot( ...
t, ...
theta3, ...
'LineStyle', astrPlotLineStyle{3}, ...
'LineWidth', afPlotLineWidth(3), ...
'Color', aafPlotLineColor(3,:), ...
'MarkerSize', aiPlotMarkerSize(3), ...
'Marker', astrPlotMarkerType{3}, ...
'MarkerFaceColor', aafPlotMarkerFaceColor(3,:), ...
'MarkerEdgeColor', aafPlotMarkerEdgeColor(3,:));

%%

%-------------------
%legends
%-------------------
atArrayOfHandlesToLines = [fig_theta1 ; fig_theta2; fig_theta3];
astrArrayOfLabels = [{'$\theta_1$ '}; {'$\theta_2$'}; {'$\theta_3$'}];
%
strLegendLocation = 'SouthOutside'; % combinations of N S E W B O or a vector
strLegendOrientation = 'horizontal'; % [{vertical} horizontal]
%
afEdgeColor = [1.0 1.0 1.0]; % RGB
afTextColor = [0 0 0]; % RGB
%
strInterpreter = 'latex'; % [{tex} | latex | none]
%
%
legend( atArrayOfHandlesToLines, ...
astrArrayOfLabels, ...
'Location', strLegendLocation, ...
'Orientation', strLegendOrientation, ...
'Box', 'off', ... [{on} off]
'Color', 'none', ... none => transparent
'EdgeColor', afEdgeColor, ...
'TextColor', afTextColor, ...
'Interpreter', strInterpreter);
%%

%-------------------------
% Color de fondo
%-------------------------
% we select the output color
afFigureBackgroundColor = [1, 1, 1];
%
set(gcf, 'color', afFigureBackgroundColor);
set(gcf, 'InvertHardCopy', 'off');

% %colocar propiedades por defecto
% set(0, 'DefaultAxesLineStyleOrder', '-|--|:');
% set(0, 'DefaultAxesColorOrder', [0.0 0.0 0.0; 0.4 0.4 0.4; 0.6 0.6 0.6]);
pause
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%             GUARDAR COMO PDF   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% here we select which output file extension we want
bPrintOnFile_Pdf    = 1; % [0 (false)   1 (true)]
bPrintOnFile_Eps    = 0; % [0 (false)   1 (true)]


% we select the file path
%
% NOTE: do NOT insert extensions!
%strFilePath = '../images/my_figure';

% we select the printing resolution
iResolution = 150;


% we select to crop or not the figure
bCropTheFigure = 1; % [0 (false)   1 (true)]


% ATTENTION: if PaperPositionMode is not 'auto' the saved file
% could have different dimensions from the one shown on the screen!
set(gcf, 'PaperPositionMode', 'auto');        


% saving on file: requires some checks
if( bPrintOnFile_Pdf || bPrintOnFile_Eps )
    %
    % NOTE: if you want a .pdf with encapsulated fonts you need to save an
    % .eps and then convert it => it is always necessary to produce the .eps
    %
    % if we want to crop the figure we do it
    if( bCropTheFigure )
        print('-depsc2', sprintf('-r%d', iResolution), strcat(strFilePath, '.eps'));
    else
        print('-depsc2', '-loose', sprintf('-r%d', iResolution), strcat(strFilePath, '.eps'));
    end;
    %
    % if we want the .pdf we produce it
    if( bPrintOnFile_Pdf )
        %
        % here we convert the .eps encapsulating the fonts
        system(                                                                    ...
          sprintf(                                                                 ...
            'epstopdf --gsopt=-dPDFSETTINGS=/prepress --outfile=%s.pdf  %s.eps',   ...
            strFilePath,                                                           ...
            strFilePath));
        %
    end;
    %
    % if we do not want the .eps we remove it
    if( ~bPrintOnFile_Eps )
        delete(sprintf('%s.eps', strFilePath));
    end;
    %
end;% saving on file

